home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-11 / trunc.zip / TRUNC.C < prev    next >
Text File  |  1993-04-10  |  2KB  |  64 lines

  1. /******************************************************************************
  2.  
  3.     TRUNC.C
  4.  
  5.     Clipper floor & ceiling functions (also seems to fix Int() bugs).
  6.     1993 Evolution Software Systems
  7.     
  8.     Compile using Microsoft C v7.0 as follows:
  9.     
  10.         CL /c /FPa /Gh /AL /Zl /Oaltz /Ob1cegno /Gs /W3 /WX $*.c
  11.  
  12.         FYI:    "/Ob1cegno /Gs" is equivalent to "/Ox" except "/Ox" enables
  13.                 "/Oi" which cannot be used with an alternate math library.
  14.  
  15.     Requires LLIBCA.LIB to link
  16.  
  17. ******************************************************************************/
  18.  
  19. #include    <extend.h>
  20.  
  21. extern double ceil(double), floor( double );    // LLIBCA functions
  22.  
  23. /* MANUAL
  24.  *
  25.  * Floor() - truncate numeric value downwards to an integer
  26.  *
  27.  * Model:    Floor( <nRealNum> ) --> nIntNum
  28.  *
  29.  * Args:    <nRealNum> is any numeric value to trucate down.
  30.  *
  31.  * Use:        This function is useful when a value has to be trucated downwards.
  32.  *            If <nRealNum> is not an even integer, it is demoted to the next
  33.  *            lowest integer. This should be identical to the Int() function
  34.  *            which seems to malfunction at times.
  35.  *
  36.  * Note:    Useful range is limited to C long (usuall approx. +- 2^31)
  37.  */
  38.  
  39. CLIPPER Floor( void ) {
  40.     if ( ISNUM( 1 ) )
  41.         _retnl( (long) floor( _parnd( 1 ) ) );
  42. }
  43.  
  44. /* MANUAL
  45.  *
  46.  * Ceiling() - truncate numeric value upwards to an integer
  47.  *
  48.  * Model:    Ceiling( <nRealNum> ) --> nIntNum
  49.  *
  50.  * Args:    <nRealNum> is any numeric value to trucate upwards.
  51.  *
  52.  * Use:        This function is useful when a value has to be trucated upwards.
  53.  *            If <nRealNum> is not an even integer, it is promoted to the next
  54.  *            higher integer. This is similar to the Int() function which does
  55.  *            not promote the number, but truncates it.
  56.  *
  57.  * Note:    Useful range is limited to C long (usuall approx. +- 2^31)
  58.  */
  59.  
  60. CLIPPER Ceiling( void ) {
  61.     if ( ISNUM( 1 ) )
  62.         _retnl( (long) ceil( _parnd( 1 ) ) );
  63. }
  64.